/**
 * this schedulers is save sccess recored to server in every 10 seconds
 */
import axios from '@/plugins/axios';
import accessStore from "@/store/AccessStore";

export default setInterval(() => {

    const records = [].concat(accessStore.state.access_records);
    if (!records || records.length == 0) return;

    const options = {url: 'forum/access/record', data: {models: records}, method: "post"}
    accessStore.commit('clear_records')

    axios(options).then(() => {}).catch(() => {
        accessStore.commit('set_records', records.concat(accessStore.state.access_records)); //restore state when error
    });


}, 10 * 1000);